package com.example.myapplication4

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity

class EditInfoActivity : AppCompatActivity() {
    private lateinit var nameEt: EditText
    private lateinit var genderEt: EditText
    private lateinit var phoneEt: EditText

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main2)

        nameEt = findViewById(R.id.name_et)
        genderEt = findViewById(R.id.gender_et)
        phoneEt = findViewById(R.id.phone_et)
        val saveBtn = findViewById<Button>(R.id.save_btn)

        val intent = intent
        nameEt.setText(intent.getStringExtra("name"))
        genderEt.setText(intent.getStringExtra("gender"))
        phoneEt.setText(intent.getStringExtra("phone"))

        saveBtn.setOnClickListener {
            val result = Intent().apply {
                putExtra("name", nameEt.text.toString())
                putExtra("gender", genderEt.text.toString())
                putExtra("phone", phoneEt.text.toString())
            }
            setResult(RESULT_OK, result)
            finish()
        }
    }
}